package com.ruoyi.web.controller.business;

import com.ruoyi.business.domain.TAccountLog;
import com.ruoyi.business.service.ITAccountLogService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 账变流水Controller
 * 
 * @author ruoyi
 * @date 2024-02-26
 */
@Controller
@RequestMapping("/business/accountLog")
public class TAccountLogController extends BaseController
{
    private String prefix = "business/accountLog";

    @Autowired
    private ITAccountLogService tAccountLogService;

    @RequiresPermissions("business:accountLog:view")
    @GetMapping()
    public String accountLog()
    {
        return prefix + "/accountLog";
    }

    /**
     * 查询账变流水列表
     */
    @RequiresPermissions("business:accountLog:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TAccountLog tAccountLog)
    {
        startPage();
        List<TAccountLog> list = tAccountLogService.selectTAccountLogList(tAccountLog);
        return getDataTable(list);
    }

    /**
     * 导出账变流水列表
     */
    @RequiresPermissions("business:accountLog:export")
    @Log(title = "账变流水", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TAccountLog tAccountLog)
    {
        List<TAccountLog> list = tAccountLogService.selectTAccountLogList(tAccountLog);
        ExcelUtil<TAccountLog> util = new ExcelUtil<TAccountLog>(TAccountLog.class);
        return util.exportExcel(list, "账变流水数据");
    }

    /**
     * 新增账变流水
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存账变流水
     */
    @RequiresPermissions("business:accountLog:add")
    @Log(title = "账变流水", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TAccountLog tAccountLog)
    {
        return toAjax(tAccountLogService.insertTAccountLog(tAccountLog));
    }

    /**
     * 修改账变流水
     */
    @RequiresPermissions("business:accountLog:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TAccountLog tAccountLog = tAccountLogService.selectTAccountLogById(id);
        mmap.put("tAccountLog", tAccountLog);
        return prefix + "/edit";
    }

    /**
     * 修改保存账变流水
     */
    @RequiresPermissions("business:accountLog:edit")
    @Log(title = "账变流水", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TAccountLog tAccountLog)
    {
        return toAjax(tAccountLogService.updateTAccountLog(tAccountLog));
    }

    /**
     * 删除账变流水
     */
    @RequiresPermissions("business:accountLog:remove")
    @Log(title = "账变流水", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tAccountLogService.deleteTAccountLogByIds(ids));
    }
}
